// 获取集合全部信息
const client = require("../db.js");

const db = client.db(global.config.db.name); // 获取数据库对象（虽然已经在URI中指定，但这里可以再次确认）

let getDataInfo = (query, dbName, isOne = false) => {
  return new Promise(async (resolve, reject) => {
    try {
      const collection = db.collection(dbName); // 获取集合对象

      const stats = await collection.stats();

      resolve({
        code: 20000,
        data: stats,
        msg: "操作成功",
      });
    } catch (error) {
      resolve({
        code: 50000,
        data: null,
        msg: "操作失败",
      });
    }
  });
};

module.exports = getDataInfo;
